#import <UIKit/UIKit.h>
#import "MRViewController.h"

typedef enum {
    IMAGE_SUCCESS   = 0,
    IMAGE_FAILURE   ,
    IMAGE_PROGRESS  ,
} HUDIMAGESTYLE;

//=================================================
@interface HUDImageLayer : CALayer

@property (nonatomic) HUDIMAGESTYLE     imgStyle;
@property (nonatomic) CGFloat           progress;

@end

//=================================================
@interface HUDImageView : UIImageView

@property (nonatomic) HUDImageLayer		*imgLayer;

@end

//=================================================
typedef NS_ENUM(NSInteger, MRPopupSytle) {
    MRPopupStyleBottom		= 0,				// 从底部滑出菜单
    MRPopupStyleTop			,					// 从顶部滑出菜单
    MRPopupStyleAlert		,					// 中间缩放模式(对话框)
};

typedef void(^DismissHandler)(BOOL finished, BOOL userDismiss);

@interface MRPopupView : UIView
{
	UIWindow    *_window;
    UIView      *_superView;
	NSArray		*_constraint;
	
    MRPopupSytle		_style;
	DismissHandler		_handler;
    
    UIViewController    *_viewController;
    NSLayoutConstraint  *_layoutControl;
	
	NSArray	<__kindof NSLayoutConstraint *>		*_constraints;
}

@property (nonatomic) CGFloat	blurRadius;		//模糊半径，默认0不模糊
@property (nonatomic) UIColor	*blurColor;		//模糊颜色，默认rgba(0,0,0,.3)

@property (nonatomic) BOOL      clickDismiss;	//默认YES

@property (nonatomic, readonly) UIImageView		*overlay;

- (void)showView:(UIView *)view style:(MRPopupSytle)style;
- (void)showView:(UIView *)view style:(MRPopupSytle)style size:(CGSize)size;
- (void)showView:(UIView *)view superview:(UIView *)superview style:(MRPopupSytle)style;
- (void)showView:(UIView *)view superview:(UIView *)superview style:(MRPopupSytle)style handler:(DismissHandler)handler;
- (void)showView:(UIView *)view superview:(UIView *)superview style:(MRPopupSytle)style size:(CGSize)size handler:(DismissHandler)handler;

- (void)dismiss;
- (void)dismissWithAnimated:(BOOL)animated;

@end

//=================================================
@interface MRHud : UIView
{
    NSLayoutConstraint      *_layoutWidth;
    NSLayoutConstraint      *_layoutHieght;
    
    MRPopupView				*_popupView;
}

@property (nonatomic, weak) IBOutlet UIActivityIndicatorView	*indicator;
@property (nonatomic, weak) IBOutlet HUDImageView				*imageView;
@property (nonatomic, weak) IBOutlet MRLabel					*message;

+ (MRHud *)hud;

+ (BOOL)visible;
+ (void)setBlurRadius:(CGFloat)radius withColor:(UIColor *)color;

+ (void)show;
+ (void)showWithMessage:(NSString *)string;
+ (void)showProgressWithMessage:(NSString *)string;

+ (void)updateProgress:(CGFloat)progress;

+ (void)dismiss;
+ (void)dismissWithAnimated:(BOOL)animated;

+ (void)dismissWithSuccess:(NSString *)string;
+ (void)dismissWithSuccess:(NSString *)string afterDelay:(CGFloat)afterDelay;

+ (void)dismissWithFailure:(NSString *)string;
+ (void)dismissWithFailure:(NSString *)string afterDelay:(CGFloat)afterDelay;

//显示成功或失败信息，延时后自动退出
+ (void)showWithSuccess:(NSString *)string;
+ (void)showWithSuccess:(NSString *)string afterDelay:(CGFloat)afterDelay;

+ (void)showWithFailure:(NSString *)string;
+ (void)showWithFailure:(NSString *)string afterDelay:(CGFloat)afterDelay;

@end
